home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / cron.weekly / popularity-contest < prev    next >
Text File  |  2008-10-20  |  2KB  |  92 lines

  1. #!/bin/sh
  2.  
  3. # don't run if this package is removed but not purged
  4. if [ ! -f /usr/sbin/popularity-contest ]; then
  5.     exit 0
  6. fi
  7.  
  8. unset MAILFROM
  9. unset MAILTO
  10. unset MY_HOSTID
  11. unset PARTICIPATE
  12. unset SUBMITURLS
  13. unset USEHTTP
  14.  
  15. # get configuration information
  16. . /usr/share/popularity-contest/default.conf
  17. . /etc/popularity-contest.conf
  18.  
  19. # don't run if MAILTO address is blank, and not configured to use HTTP POST!
  20. if [ -z "$MAILTO" ] && [ "yes" != "$USEHTTP" ]; then exit 0; fi
  21.  
  22. # don't run if PARTICIPATE is "no" or unset!
  23. [ "$PARTICIPATE" = "no" ] || [ -z "$PARTICIPATE" ] && exit 0
  24.  
  25. if [ -n "$HTTP_PROXY" ]; then
  26.   export http_proxy="$HTTP_PROXY";
  27. fi
  28.  
  29. # keep old logs
  30. cd /var/log
  31. umask 022
  32. savelog -c 7 popularity-contest >/dev/null
  33. POPCON=/var/log/popularity-contest
  34.  
  35. run_popcon()
  36. {
  37.     su -s /bin/sh -c "/usr/sbin/popularity-contest" nobody
  38. }
  39.  
  40. do_sendmail()
  41. {
  42.     if [ -n "$MAILFROM" ]; then
  43.         sendmail -oi -f "$MAILFROM" $MAILTO
  44.     else
  45.         sendmail -oi $MAILTO
  46.     fi
  47. }
  48.  
  49. # generate the popularity contest data
  50.  
  51. run_popcon > $POPCON
  52.  
  53. SUBMITTED=no
  54.  
  55. # try to post the report through http POST
  56. if [ "$SUBMITURLS" ] && [ "yes" = "$USEHTTP" ]; then
  57.     for URL in $SUBMITURLS ; do
  58.     if setsid /usr/share/popularity-contest/popcon-upload \
  59.         -u $URL -f $POPCON -C 2>/dev/null ; then
  60.         SUBMITTED=yes
  61.     else
  62.         logger -t popularity-contest "unable to submit report to $URL."
  63.     fi
  64.     done
  65. fi
  66.  
  67. # try to email the popularity contest data
  68.  
  69. if [ yes != "$SUBMITTED" ] && [ -n "$MAILTO" ]; then
  70.     if [ -x "`which sendmail 2>/dev/null`" ]; then
  71.     (
  72.         if [ -n "$MAILFROM" ]; then
  73.                 echo "From: <$MAILFROM>"
  74.             echo "Sender: <$MAILFROM>"
  75.         fi
  76.         echo "To: $MAILTO"
  77.         echo "Subject: popularity-contest submission"
  78.         echo "MIME-Version: 1.0"
  79.         echo "Content-Type: text/plain"
  80.         echo
  81.         cat $POPCON
  82.     ) | do_sendmail
  83.     SUBMITTED=yes
  84.     else
  85.     logger -t popularity-contest "unable to submit report using sendmail."
  86.     fi
  87. fi
  88.  
  89. if [ "yes" != "$SUBMITTED" ] ; then
  90.     logger -t popularity-contest "unable to submit report."
  91. fi
  92.